import * as THREE from 'three';

export class ThreeFramework {
    private scene: THREE.Scene;
    private camera: THREE.PerspectiveCamera;
    private renderer: THREE.WebGLRenderer;
    private container: HTMLDivElement;

    constructor(container: HTMLDivElement, width: number, height: number) {
        this.container = container;
        this.scene = new THREE.Scene();
        this.camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
        this.camera.position.z = 5
        this.renderer = new THREE.WebGLRenderer({antialias: true});
        this.renderer.setSize(width, height);
        this.renderer.setPixelRatio(window.devicePixelRatio);
        container.appendChild(this.renderer.domElement);
    }

    public addMesh(mesh: THREE.Mesh): void {
        this.scene.add(mesh);
    }

    public removeMesh(mesh: THREE.Mesh): void {
        this.scene.remove(mesh);
    }

    public start(): void {
        const animate = () => {
            requestAnimationFrame(animate);
            this.render();
        };
        animate();
    }

    private render(): void {
        this.renderer.render(this.scene, this.camera);
    }
}